/**
 * @program: LeetCode
 * @description: LeetCode : 缺失数字
 * @author: WXY
 * @create: 2023-01-02 20:41
 * @Version 1.0
 **/
public class code_missingNumber {
    public static int missingNumber(int[] nums) {
        int max = nums.length;
        for (int num : nums) {
            max = Math.max(num, max);
        }
        int[] arr = new int[max + 1];
        for (int i = 0; i < max; i++) {
            arr[nums[i]]++;
        }
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == 0) {
                return i;
            }
        }
        return max;
    }

    public static int missingNumber1(int[] arr) {
        int ans = 0;
        for (int i = 0; i < arr.length; i++) {
            ans ^= (i + 1) ^ arr[i];
        }
        return ans;
    }

    public static void main(String[] args) {
        int[] arr = {1, 3, 4, 2, 0};
        int i = missingNumber1(arr);
        System.out.println(i);
    }

}
